#include "adas_application.h"

using namespace decision::adas;

AdasApplication::AdasApplication(World& world, const std::string& name, double fps = 0.1)
    : rclcpp::Node(name)
    , logger_(rclcpp::get_logger(name))
    , this_world_(world)
    , name_(name)
    , fps_(fps)
    , working_(false)
{
    loop_ = thread_.startLoop();
}

AdasApplication::~AdasApplication()
{
    stop();
}

const std::string& AdasApplication::name()
{
    return name_;
}

void AdasApplication::start()
{
    if (!working_) {
        timer_ = loop_->runEvery(fps_, std::bind(&AdasApplication::detect, this));
        working_ = true;
    }
}

void AdasApplication::stop()
{
    if (working_) {
        loop_->cancel(timer_);
        working_ = false;
    }
}
